using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class MemberSubscriptionDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public MemberSubscriptionDA()
		{
		}

		public MemberSubscriptionDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the MemberSubscription table.
		/// </summary>
		public  int Insert(MemberSubscription memberSubscription)
		{
			ValidationUtility.ValidateArgument("memberSubscription", memberSubscription);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", memberSubscription.TenantID),
				new SqlParameter("@ProfileID", memberSubscription.ProfileID),
				new SqlParameter("@SubscriptionID", memberSubscription.SubscriptionID),
				new SqlParameter("@IsActive", memberSubscription.IsActive),
				new SqlParameter("@CraetedDate", memberSubscription.CraetedDate),
				new SqlParameter("@UpdateDate", memberSubscription.UpdateDate)
			};

			memberSubscription.MemberSubscriptionID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionInsert", parameters));
			return memberSubscription.MemberSubscriptionID;
		}

		/// <summary>
		/// Updates a record in the MemberSubscription table.
		/// </summary>
		public  int Update(MemberSubscription memberSubscription)
		{
			ValidationUtility.ValidateArgument("memberSubscription", memberSubscription);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@MemberSubscriptionID", memberSubscription.MemberSubscriptionID),
				new SqlParameter("@TenantID", memberSubscription.TenantID),
				new SqlParameter("@ProfileID", memberSubscription.ProfileID),
				new SqlParameter("@SubscriptionID", memberSubscription.SubscriptionID),
				new SqlParameter("@IsActive", memberSubscription.IsActive),
				new SqlParameter("@CraetedDate", memberSubscription.CraetedDate),
				new SqlParameter("@UpdateDate", memberSubscription.UpdateDate)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberSubscription table by its primary key.
		/// </summary>
		public  int Delete(int memberSubscriptionID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@MemberSubscriptionID", memberSubscriptionID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberSubscription table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberSubscription table by a foreign key.
		/// </summary>
		public  int DeleteAllBySubscriptionID(int subscriptionID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@SubscriptionID", subscriptionID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionDeleteAllBySubscriptionID", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberSubscription table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the MemberSubscription table.
		/// </summary>
		public  MemberSubscription Select(int memberSubscriptionID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@MemberSubscriptionID", memberSubscriptionID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakeMemberSubscription(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the MemberSubscription table.
		/// </summary>
		public  List<MemberSubscription> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionSelectAll", parameters))
			{
				List<MemberSubscription> memberSubscriptionList = new List<MemberSubscription>();
				while (dataReader.Read())
				{
					MemberSubscription memberSubscription = MakeMemberSubscription(dataReader);
					memberSubscriptionList.Add(memberSubscription);
				}

				return memberSubscriptionList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberSubscription table by a foreign key.
		/// </summary>
		public  List<MemberSubscription> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionSelectAllByProfileID", parameters))
			{
				List<MemberSubscription> memberSubscriptionList = new List<MemberSubscription>();
				while (dataReader.Read())
				{
					MemberSubscription memberSubscription = MakeMemberSubscription(dataReader);
					memberSubscriptionList.Add(memberSubscription);
				}

				return memberSubscriptionList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberSubscription table by a foreign key.
		/// </summary>
		public  List<MemberSubscription> SelectAllBySubscriptionID(int subscriptionID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@SubscriptionID", subscriptionID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionSelectAllBySubscriptionID", parameters))
			{
				List<MemberSubscription> memberSubscriptionList = new List<MemberSubscription>();
				while (dataReader.Read())
				{
					MemberSubscription memberSubscription = MakeMemberSubscription(dataReader);
					memberSubscriptionList.Add(memberSubscription);
				}

				return memberSubscriptionList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberSubscription table by a foreign key.
		/// </summary>
		public  List<MemberSubscription> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberSubscriptionSelectAllByTenantID", parameters))
			{
				List<MemberSubscription> memberSubscriptionList = new List<MemberSubscription>();
				while (dataReader.Read())
				{
					MemberSubscription memberSubscription = MakeMemberSubscription(dataReader);
					memberSubscriptionList.Add(memberSubscription);
				}

				return memberSubscriptionList;
			}
		}

		/// <summary>
		/// Creates a new instance of the MemberSubscription class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  MemberSubscription MakeMemberSubscription(SqlDataReader dataReader)
		{
			MemberSubscription memberSubscription = new MemberSubscription();
			memberSubscription.MemberSubscriptionID = SqlClientUtility.GetInt32(dataReader, "MemberSubscriptionID", 0);
			memberSubscription.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			memberSubscription.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			memberSubscription.SubscriptionID = SqlClientUtility.GetInt32(dataReader, "SubscriptionID", 0);
			memberSubscription.IsActive = SqlClientUtility.GetBoolean(dataReader, "IsActive", false);
			memberSubscription.CraetedDate = SqlClientUtility.GetDateTime(dataReader, "CraetedDate", DateTime.Now);
			memberSubscription.UpdateDate = SqlClientUtility.GetString(dataReader, "UpdateDate", String.Empty);

			return memberSubscription;
		}

		#endregion
	}
}
